package cn.tedu.toa.management.sys.controller;


import cn.tedu.toa.management.commons.vo.Result;
import cn.tedu.toa.management.sys.entity.FKeyservices;
import cn.tedu.toa.management.sys.entity.SysUsers;
import cn.tedu.toa.management.sys.service.FKeyservicesService;
import cn.tedu.toa.management.sys.vo.KeyServiceVo;
import cn.tedu.toa.management.util.UploadUtils;
import cn.tedu.toa.management.util.UserUtils;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * <p>
 * 特色服务表 前端控制器
 * </p>
 *
 * @author huaqian
 * @since 2021-10-02
 */
@RestController
@RequestMapping("/f-keyservices")
@Slf4j
public class FKeyservicesController {
    @Value("${myconfig.page-size}")
    private Integer pageSize;

    @Autowired
    private FKeyservicesService keyservicesService;

    @GetMapping("/getMenus")
    public List<FKeyservices> menus(){
        return keyservicesService.getMenus();
    }

    @GetMapping("/getServiceVo")
    public KeyServiceVo getServiceVo(String name){
        return keyservicesService.getServiceVo(name);
    }

    @GetMapping("/getServiceByName")
    public FKeyservices getServiceByName(String name){
        return keyservicesService.getService(name);
    }

    @PostMapping("/edit")
    public Result edit(FKeyservices keyService){
        log.debug("修改的内容:{}",keyService);
        keyservicesService.edit(keyService,UserUtils.getCurrentUserName());
        return Result.ok();
    }

    @PostMapping("/insert")
    public Result insert(FKeyservices keyService){
        log.debug("新增的内容:{}",keyService);
        keyservicesService.insert(keyService,UserUtils.getCurrentUserName());
        return Result.ok();
    }

    //删除
    @GetMapping("/delete")
    public Result delete(Integer id){
        log.debug("删除的内容id:{}",id);
        keyservicesService.delete(id);
        return Result.ok();
    }

    @GetMapping("/findKeyServicesList")
    public Result<PageInfo<FKeyservices>> findKeyServicesList(String name,
                                                   @RequestParam(defaultValue = "1") Integer pageNum){
        PageInfo<FKeyservices> pageInfo=keyservicesService.findKeyServicesList(name,pageNum,pageSize);
        return Result.ok(pageInfo);
    }

    @PostMapping("/uploadImg")
    public Result uploadImg(MultipartFile imageFile){
        String url = keyservicesService.uploadImg(imageFile);
        return Result.ok(url);
    }
}
